﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChanExt;
using C.Unite;
using C.Entities;
using MySoft.Data;

namespace ArtLand.OA.Project.SystemMgr
{
    public partial class SysModelPerChange : CommonPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();

            }

        }

        private void LoadData()
        {

            // 关闭按钮的客户端脚本：
            // 1. 首先确认窗体中表单是否被修改（如果已经被修改，则弹出是否关闭的确认对话框）
            // 2. 然后关闭本窗体，回发父窗体
            btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
            int id = 0;
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                id = int.Parse(Request["id"]);
            }
            if (id > 0)
            {
                Sys_ModPermis tmp = TbsDbSession.Default.From<Sys_ModPermis>().Where(Sys_ModPermis._.Perid == id).ToFirst();
                txt_isuser.Checked = tmp.IsUser.Value;
                txt_keyword.Text = tmp.Keyword;
                txt_memo.Text = tmp.Memo;
                txt_Orderid.Text = tmp.Orderid.Value.ToString();
                txt_Pername.Text = tmp.Pername;
            }
        }


        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            int returnvalue = 0;
            Sys_ModPermis tm = new Sys_ModPermis();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                tm.Perid = int.Parse(Request["id"]);
                tm.Attach();
                tm.Pername = txt_Pername.Text;
                tm.Keyword = txt_keyword.Text;
                tm.IsUser = txt_isuser.Checked;
                tm.Orderid = int.Parse(txt_Orderid.Text);
                tm.Memo = txt_memo.Text;
                returnvalue = TbsDbSession.Default.Update<Sys_ModPermis>(tm);

            }
            else
            {
                tm.DeAttach();
                tm.Pername = txt_Pername.Text;
                tm.Keyword = txt_keyword.Text;
                tm.IsUser = txt_isuser.Checked;
                tm.Orderid = int.Parse(txt_Orderid.Text);
                tm.Memo = txt_memo.Text;
                returnvalue = TbsDbSession.Default.Insert<Sys_ModPermis>(tm);
            }
            if (returnvalue > 0)
            {
                PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            }
        }


        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    Alert.Show("提示内容");
        //}
    }
}